<!-- Wrapper functions
Avoid referring to actual element IDs/names from within js file.
Changes to elements should only involve edits within this file.
-->
<script type="text/javascript">
function _addPredicate() {
	addContentToText(
			document.getElementById("publication_text")
		,document.getElementById("attribute_text").value
		,""
		,document.getElementById("value_text").value
		);
		
		document.getElementById("attribute_text").focus();
}
function _addPredicates() {
	var option=document.getElementById("pub_preds_option");
	addToText(
		document.getElementById("publication_text")
		,option.options[option.selectedIndex].value + "\n"
		);
}
function _publish() {
	var option=document.getElementById("broker_option");
	if (option.selectedIndex < 0) {
		alert("Not connected to any Brokers");
		return;
	}
	publish(
		document.getElementById("publication_text").value
		,option.options[option.selectedIndex].value
		,document.getElementById("auto_advertise_check").checked
		);
}
function _loadFile() {
	loadFile(
		document.getElementById("filename_text").value,
		MSG_TYPE_PUB
		);
}
</script>

<div id="publication_panel_closed" class="panel" style="display: none;">
<a href="#" class="hide" onclick="togglePanels(document.getElementById('publication_panel_closed'), document.getElementById('publication_panel_open'));"><img src="images/expand.png"></a>
</div>
<div id="publication_panel_open" class="panel">
<a href="#" class="hide" onclick="togglePanels(document.getElementById('publication_panel_closed'), document.getElementById('publication_panel_open'));"><img src="images/collapse.png"></a>
	<div id="publication_content" class="content">
		
		<h3>
			<img src="images/publish.png" />
			Issue Publication
		</h3>
		
		<form id="predicate_form" onmousedown="startResize(document.getElementById('predicate_form'), document.getElementById('publication_panel_open'), 46);"
			onmouseover="highlight(this);"
			onmouseout="unhighlight(this);"
		>
			<div class="labels">
				<input type="label" readonly="true" value="Attr:"/> <br />
				<input type="label" readonly="true" value="Val:" />
			</div>
			<div class="inputs">
				<input type="text" id="attribute_text"/> <br />
				<input type="text" id="value_text"/>
			</div>
			<div class="right_align">
			<input type="button" value="Add Tuple" onclick="_addPredicate()" />
			</div>
		</form>
		
		<form id="publication_form" onmousedown="startResize(document.getElementById('publication_text'), document.getElementById('publication_panel_open'), 46);"
			onmouseover="highlight(this);"
			onmouseout="unhighlight(this);"
		>
		<textarea id="publication_text"></textarea>
		<div class="right_align">
		<input type="button" value="Clear" onclick="clearText(document.getElementById('publication_text'))" />
			<input type="button" value="Publish" onclick="_publish()" />
		</div>
		</form>
	</div>
</div>
		
<div id="pub_advanced_panel_closed" class="panel" style="display: none;">
	<a href="#" class="hide" onclick="togglePanels(document.getElementById('pub_advanced_panel_closed'), document.getElementById('pub_advanced_panel_open'));"><img src="images/expand.png"></a>
</div>
<div id="pub_advanced_panel_open" class="panel">
	<a href="#" class="hide" onclick="togglePanels(document.getElementById('pub_advanced_panel_closed'), document.getElementById('pub_advanced_panel_open'));"><img src="images/collapse.png"></a>
	<div id="pub_advanced_content" class="content">
		<h3>
			<img src="images/advanced.png" />
			Advanced
		</h3>
		
		<form id="pub_preds_form" onmousedown="startResize(document.getElementById('pub_preds_form'), document.getElementById('pub_advanced_panel_open'), 46);">
			<div class="labels">
				<input type="label" readonly="true" value="File:" /> <br />
				<input type="label" readonly="true" value=""/> <br />
				<input type="label" readonly="true" value="Tuples:"/>
			</div>
			<div class="inputs">
				<input type="file" id="filename_text" /> <br />
				<input type="label" readonly="true" value=""/> <br />
				<select id="pub_preds_option"></select> <br />
				<div class="right_align">
				<input type="button" value="Load File" onclick="_loadFile()" />
				<input type="button" value="Add Tuples(s)" onclick="_addPredicates()" />
				</div>
			</div>
		</form> 
		
		<form id="broker_form" onmousedown="startResize(document.getElementById('broker_form'), document.getElementById('pub_advanced_panel_open'), 46);">
			<div class="labels">
				<input type="label" readonly="true" value="Brokers:" />
			</div>
			<div class="inputs">
				<select id="broker_option"></select>
			</div>
			<div class="right_align">
				<input type="button" value="Refresh" onclick="loadBrokers()" />
			</div>
		</form>

		<form id="pub_options_form" onmousedown="startResize(document.getElementById('pub_options_form'), document.getElementById('pub_advanced_panel_open'), 46);">
			<input type="checkbox" id="auto_advertise_check" value="Auto-Advertise" checked="true" /> Auto-Advertise
		</form>
	</div>

</div>

<div id="messages_panel_closed" class="panel" style="display: none;">
	<a href="#" class="hide" onclick="togglePanels(document.getElementById('messages_panel_closed'), document.getElementById('messages_panel_open'));"><img src="images/expand.png"></a>
</div>
<div id="messages_panel_open" class="panel">
	<a href="#" class="hide" onclick="togglePanels(document.getElementById('messages_panel_closed'), document.getElementById('messages_panel_open'));"><img src="images/collapse.png"></a>
	<div id="messages_content" class="content" onmousedown="startResize(document.getElementById('advertisement_list_form'), document.getElementById('messages_panel_open'), 46);">
		
		<h3>
			<img src="images/advertisements.png" />
		Active Advertisements
		</h3>
		
		<form id="advertisement_list_form" onmousedown="startResize(this, document.getElementById('messages_panel_open'), 46)"
			onmouseover="highlight(this);"
			onmouseout="unhighlight(this);"
		>
			<input type="button" value="Refresh" onclick="refreshActiveAdvertisements()" />
			<div id="advertisement_list" class="message_list">
			</div>
		</form>	
	</div>
	</script>
</div>

		
<script type="text/javascript">
	// initializations once divs are loaded
	setAdvListElem(document.getElementById("advertisement_list"));
	setPubOptionElem(document.getElementById("pub_preds_option"));
	setBrokerOptionElem(document.getElementById("broker_option"));

	loadBrokers();
	refreshActiveAdvertisements();

	setPageTitleText("Publish");
	// start event listening
	// startEvents(DEFAULT_WEBUI_QID);
</script>
